package cn.egame.extraction.dao;

import java.util.List;

import cn.egame.common.data.BaseDao;
import cn.egame.common.exception.ExceptionCommonBase;

public class ReportGameDayDownDao extends BaseDao {

	private static final String select_All_GId = "select distinct(g_id) from egame_log.t_report_game_day_down ";

	private static final String select_COUNT_FULL_GId = "SELECT sum(day_counts_total)  from egame_log.t_report_game_day_down ";

	private static final String select_COUNT_INCR_GId = "SELECT sum(day_counts_incr)  from egame_log.t_report_game_day_down ";

	public ReportGameDayDownDao() throws ExceptionCommonBase {
		super("egame_log");
	}

	public List<Integer> listReportGameDayDownGId() throws ExceptionCommonBase {
		return this.getListInteger(select_All_GId);
	}

	public int getReportGameDayDownCountByDay(int gId)
			throws ExceptionCommonBase {

		String sql = select_COUNT_FULL_GId + " where g_id=" + gId
				+ " and date=curdate()  ";
		return this.getInt(sql);
	}
	
	
	public int getReportGameDayDownCountByWeek(int gId)
			throws ExceptionCommonBase {

		String sql = select_COUNT_FULL_GId + " where g_id=" + gId
				+ " and date>=date_sub(curdate(),interval 7 day)";
		return this.getInt(sql);
	}
	
	
	
	public int getReportGameDayDownCountByMonth(int gId)
			throws ExceptionCommonBase {

		String sql = select_COUNT_FULL_GId + " where g_id=" + gId
				+ " and date>=date_sub(curdate(),interval 30 day)";
		return this.getInt(sql);
	}
	
	
	
	public int getReportGameDayDownCountIncrByDate(int gId)
			throws ExceptionCommonBase {

		String sql = select_COUNT_INCR_GId + "where  date=curdate() and g_id ="
				+ gId;
		return this.getInt(sql);
	}

	public int updateReportGameDayDownCountIncr(int gId) throws ExceptionCommonBase {
		String sql = "update t_report_game_day_down set day_counts_incr =0 where date=curdate() and g_id="
				+ gId;
		return this.executeUpdate(sql);
	}
}
